#### Ref: "Appendix" from <<tmux: productive mouse free development>> book.
#### Some keybindings
# unbind the default prefix
unbind C-b

# bind prefix to C-l since C-l is rarely used
set -g prefix C-l

# workaround for `open` command in OS X terminal with tmux
# ref: https://github.com/atom/atom/issues/3093
set-option -g default-command "which reattach-to-user-namespace > /dev/null && reattach-to-user-namespace -l $SHELL || $SHELL"

# reload the configuration
# bind a key to a series of commands by separating the commands with the \;
# character combination.
bind r source-file ~/.tmux.conf \; display "tmux.conf reloaded!"

# splitting panes with visual shortcuts, | for horizontal, - for vertical
# And we want newer window/pane born with the same directory as before
# refs: http://unix.stackexchange.com/questions/12032/create-new-window-with-current-directory-in-tmux
bind | split-window -c "#{pane_current_path}" -h
bind % split-window -c "#{pane_current_path}" -h
bind - split-window -c "#{pane_current_path}" -v
bind '"' split-window -c "#{pane_current_path}" -v

bind c new-window -c "#{pane_current_path}"

# remapping movement keys
# using vim's hjkl for movement
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# use PREFIX CTRL-h and PREFIX CTRL-l to cycle through the windows
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+

# resizing panes
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

#### Some basic settings
# changing the default delay
set -sg escape-time 1

#### setting the windows and panes index starting from 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1

# mouse in tmux
# seems tmux mouse mode don't work in Mac OSX's default Terminal.app
# You need to intall iTerm2(http://iterm2.com/).
# !IMPORTANT!: If you enable this in tmux, you will not able select text in
# tmux window in normal ways,
# Refs: https://awhan.wordpress.com/2012/04/18/tmux-copy-paste-with-mouse/
# setw -g mode-mouse on
# set -g mouse-select-pane on
# set -g mouse-resize-pane on
# set -g mouse-select-window on

# configuring colors
set -g default-terminal "screen-256color"

# use vim keys in copy mode
setw -g mode-keys vi

#### The awesome status line
# enable activity alerts
setw -g monitor-activity on
set -g visual-activity on

# set the status line's colors
set -g status-fg white
set -g status-bg black

# Status line left side
set -g status-left-length 40
set -g status-left "#[fg=green]Session: #S #[fg=yellow]#I #[fg=cyan]#P"

# Status line right side
# Update the status bar every sixty seconds
set -g status-interval 60

# Center the window list
set -g status-justify centre
